<?php 
namespace Home\Controller;
use Think\Controller;
class ShopController extends Controller {
/**
 * 新增商品
 * @return [type] [description]
 */
	public function addshop() {
		if (!IS_POST) {
			$this->display();
		} else {
			$shop = D('shop');
    		$_POST['pubtime'] = time();
    		if ($shop->create()) {
    			$result = $shop->add();
    			if ($result) {
    				$this->success('商品添加成功');
    			} else {
    				$this->error('商品添加失败');
    			}
    		}
		}
	}
/**
 * 商品列表
 */
	public function listshop() {
		$shop = D('shop');
		$count  = $shop->count();// 查询满足要求的总记录数
    $Page   = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    $show   = $Page->show();// 分页显示输出
    // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
    $data = $shop->order('pubtime')->limit($Page->firstRow.','.$Page->listRows)->select();
    $this->assign('page',$show);// 赋值分页输出
    $this->assign('data' , $data);
		$this->display();
	}
/**
  * 商品修改
  * @return [type] [description]
  */
 	public function editshop($sid) {
 		$shop = D('shop');
 		if (!IS_POST) {
 			$data = $shop->find($sid);
 			$this->assign('data' , $data);
    		$this->display();
    	} else { 
    		if ($shop->where("sid='$sid'")->save($_POST)) {    	
    			$this->success('商品修改成功');    				
    		} else {
    			$this->error('商品修改失败');
    		}
    	}
 	}
 /**
  * 商品删除
  * @return [type] [description]
  */
 	public function delshop($sid) {
 		$shop = D('shop');
 		if ($shop->delete($sid)) {
 			$this->redirect('Home/Shop/listshop');
 		} 
 	}
  /**
   * 财务报表
   */
  public function listcw() {   
    $Model = new \Think\Model(); // 实例化一个model对象 没有对应任何数据表  
    $count = $Model->query("select count(*) as a from pay");// 查询满足要求的总记录数
    $count = $count[0]['a'];       
    $Page  = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    $show  = $Page->show();// 分页显示输出 
    $data = $Model->query("select a.pid,a.name,b.name as shopname,a.money,a.pubtime from pay as a,shop as b where a.shopname=b.sid order by pubtime desc limit ".$Page->firstRow.','.$Page->listRows);    
    $pay = D('pay');      
    $this->assign('page',$show);// 赋值数据集
    $money = $pay->sum('money');
    $this->assign('money',$money);    
    $this->assign('data',$data);
    $this->display();
  }
  /**
   * 充值报表
   */
  public function listcz() {   
    $cdk = D('cdk');
    $count  = $cdk->count();// 查询满足要求的总记录数
    $Page   = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    $show   = $Page->show();// 分页显示输出
    // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
    $data = $cdk->order('pubtime')->limit($Page->firstRow.','.$Page->listRows)->select();
    $this->assign('page',$show);// 赋值分页输出
    $this->assign('data' , $data);    
    $money = D('cdk')->sum('money');
    $this->assign('money',$money);  
    $this->display();
  }



}




 ?>